package com.movie.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDate;
import java.time.LocalDateTime;


/**
 * 前端用户实体
 * 用于电影网站的前端用户（普通观众）
 */
@Data
@Entity
@Table(name = "users")
public class User {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @NotBlank(message = "用户名不能为空")
    @Column(nullable = false, unique = true)
    private String username;
    
    @NotBlank(message = "邮箱不能为空")
    @Email(message = "邮箱格式不正确")
    @Column(nullable = false, unique = true)
    private String email;
    
    @NotBlank(message = "密码不能为空")
    @Column(nullable = false)
    private String password;
     
    @Size(max = 500, message = "个人简介不能超过500个字符")
    @Column(name = "bio", length = 500)
    private String bio;
    
    @Column(name = "birthday")
    private LocalDate birthday;
    
    @Column(name = "avatar_url")
    private String avatarUrl;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "vip_level_id")
    private VipLevel vipLevel;
    
    @Column(name = "vip_expire_date")
    private LocalDateTime vipExpireDate;
    
    @Column(name = "points", nullable = false)
    private Integer points = 0;
    
   
    
    @Column(nullable = false)
    private Boolean status = true;
    
    @Column(name = "last_login")
    private LocalDateTime lastLogin;
    
    @CreationTimestamp
    @Column(name = "created_at", updatable = false)
    private LocalDateTime createdAt;
    
    @UpdateTimestamp
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;
}